const db = require('../../config/dbconfig');

// 添加日志
const addLog = async (req, res) => {
  const { level, message } = req.body;
  const sql = 'INSERT INTO logs SET ?';
  const values = { level, message };
  db.query(sql, values, (err, results) => {
    if (err) return res.cc(err);
    res.cc('日志添加成功', 0);
  });
};

// 获取日志列表
const getLogs = async (req, res) => {
  const sql = 'SELECT * FROM logs ORDER BY created_at DESC';
  db.query(sql, (err, results) => {
    if (err) return res.cc(err);
    res.send({
      status: 0,
      data: results
    });
  });
};

module.exports = {
  addLog,
  getLogs
};